#!/bin/bash

# 本脚本已通过Mac、CentOS的校验（排除内存型号）！

# 定义颜色代码
BLACK='\033[0;30m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
WHITE='\033[0;37m'
RESET='\033[0m'

# 获取 CPU 型号和核心数
if [ "$(uname)" == "Darwin" ]; then
    cpu_model=$(sysctl -n machdep.cpu.brand_string)
    cpu_cores=$(sysctl -n hw.physicalcpu)
    system_type="Mac"
else
    cpu_model=$(lscpu | grep "Model name" | awk -F':' '{print $2}' | xargs)
    cpu_cores=$(lscpu | grep "Core(s) per socket" | awk -F':' '{print $2}' | xargs)
    if [ -f /etc/os-release ]; then
        if grep -q "NAME=\"Ubuntu\"" /etc/os-release; then
            system_type="Ubuntu"
        elif grep -q "NAME=\"Debian\"" /etc/os-release; then
            system_type="Debian"
        elif grep -q "NAME=\"CentOS Linux\"" /etc/os-release; then
            system_type="CentOS"
        else
            system_type="Linux"
        fi
    else
        system_type="Linux"
    fi
fi

# 获取内存型号和大小
if [ "$(uname)" == "Darwin" ]; then
    memory_model="N/A (Mac系统不支持直接获取内存型号)"
    memory_size=$(system_profiler SPHardwareDataType | grep "Memory:" | awk '{print $2}')
else
    memory_model=$(sudo dmidecode -t 17 2>/dev/null | grep "Part Number" | awk -F':' '{print $2}' | xargs)
    memory_size=$(free -h | awk '/^Mem:/ {print $2}')
fi

# 获取系统版本和内核信息
if [ "$(uname)" == "Darwin" ]; then
    os_version=$(sw_vers -productVersion)
    kernel_version=$(uname -r)
else
    os_version=$(cat /etc/*release | grep "PRETTY_NAME" | awk -F'=' '{print $2}' | tr -d '"')
    kernel_version=$(uname -r)
fi

# 输出获取的信息
echo -e "${GREEN}"
echo "系统类型: $system_type $os_version"
echo "系统内核: $kernel_version"
echo -e "${YELLOW}"
echo "CPU 型号: $cpu_model"
echo "CPU 核心数: $cpu_cores"
echo -e "${RED}"
echo "内存型号: $memory_model"
echo "内存大小: $memory_size"
echo -e "${RESET}"
